<?php 
	
	$menu = array();
	
		$menu["home"] = array(
			"title"	=> "Dashboard",
			"url" 	=> "|index"
		);
		
		$menu["categories"] = array(
			"title"	=> "Categorias",
			"url" 	=> "categories",
			"menu"	=> array(
				"list"	=> array(
					"url" 	=> "categories|categories/index|categories/index",
					"title"	=> "Listado de Categorias"
				),
				"add"	=> array(
					"url"	=> "categories/add",
					"title"	=> "Añadir una nueva Categoria"
				)
			)
		);
		$menu["tags"] = array(
			"title"	=> "Etiquetas",
			"url" 	=> "tags",
			"menu"	=> array(
				"list"	=> array(
					"url" 	=> "tags|tags/index|tags/edit",
					"title"	=> "Listado de Etiquetas"
				),
				"add"	=> array(
					"url"	=> "tags/add",
					"title"	=> "Añadir una nueva Etiqueta"
				)
			)
		);
		$menu["nodes"] = array(
			"title"	=> "Contenidos",
			"url" 	=> "nodes",			
			"menu"	=> array(
				"list"	=> array(
					"url" 	=> "nodes|nodes/index|nodes/edit",
					"title"	=> "Todos"
				)
			)
		);
		
		$types = $this->settings->item("content_types");
		foreach($types as $type_name=>$type){
			$menu["nodes"]["menu"][$type_name] = array(
				"url" => "nodes?type=$type_name",
				"title"	=> "{$type['title']}"
			);
		}
		
		$menu["nodes"]["menu"]["add"] = array(
			"url"	=> "nodes/add|nodes/proccess",
			"title"	=> "Añadir un nuevo Contenido"
		);
		
		$menu["comments"] = array(
			"url"	=> "comments",
			"title"	=> "Comentarios"
		);
		
		$menu["links"] = array(
			"title"	=> "Enlaces",
			"url" 	=> "links",
			"menu"	=> array(
				"list"	=> array(
					"url" 	=> "links|links/index|links/edit",
					"title"	=> "Listado de Enlaces"
				),
				"add"	=> array(
					"url"	=> "links/add",
					"title"	=> "Añadir un nuevo Enlace"
				)
			)
		);
		$menu["users"] = array(
			"title"	=> "Usuarios y Grupos",
			"url" 	=> "users",			
			"menu"	=> array(
				"list"	=> array(
					"url" 	=> "users|users/index|users/edit|users/delete",
					"title"	=> "Listado de Usuarios"
				),
				"add"	=> array(
					"url"	=> "users/add",
					"title"	=> "Añadir un nuevo usuario"
				),
				"group_list"	=> array(
					"url" 	=> "users/group_list|users/group_edit|users/group_delete",
					"title"	=> "Listado de Grupos"
				),
				"group_add"	=> array(
					"url"	=> "users/group_add",
					"title"	=> "Añadir un nuevo Grupo"
				),
				"my_account"	=> array(
					"url"	=> "users/my_account",
					"title"	=> "Editar mi perfil"
				)
			)
		);
		
		$menu["options"] = array(
			"title"	=> "Settings",
			"url"	=> "options",			
			"menu"	=> array()		
		);
	
	
	$groups = $this->settings->item("groups");
	foreach($groups as $group_name=>$group){
		$menu['options']['menu'][$group_name] = array(
			"url" 	=> "options/$group_name",
			"title"	=> $group['title']
		);
	}
	
	
?>		
<div id="sidebar"><div id="sidebar-wrapper"> <!-- Sidebar with logo and menu -->
	
	<h1 id="sidebar-title"><a href="#">Simpla Admin</a></h1>
  
	<!-- Logo (221px wide) -->
	<a href="#"><img id="logo" src="<?php echo static_url("images/logo.png"); ?>" alt="Simpla Admin logo" /></a>
  
	<!-- Sidebar Profile links -->
	<div id="profile-links">
		Hola, <?php echo anchor("admin/users/my_account", $login_user->first_name)?>, you have <a href="#messages" rel="modal" title="3 Messages">3 Messages</a><br />

		<br />
		<?php echo anchor("admin/users/my_account", "Editar Perfil")?> | <?php echo anchor("admin/logout", "Salir")?>
	</div>        
	
	<ul id="main-nav">
		<?php foreach($menu as $menu_item):?>
			<?php 	
				$title = $menu_item['title'];
				$url = split("\|", $menu_item['url']); 
				$active = false;
				if(in_array($this->uri->segment("2"), $url)){
					$active = true;
				}
				
				$url = $url[0];
			?>
			<!-- Añadir class current al a activo -->
			<li>
				<a href="<?php echo site_url("admin/$url"); ?>" class="nav-top-item <?php if(!isset($menu_item['menu'])) echo "no-submenu"; ?> <?php if($active) echo "current"; ?>"><?php echo $title; ?></a>
				<?php if(isset($menu_item['menu'])): ?>
					<ul>
					<?php foreach($menu_item['menu'] as $submenu_item):?>
						<?php 	
							$stitle = $submenu_item['title'];
							$surl = split("\|", $submenu_item['url']); 
							
							$sactive = false;
							foreach($surl as $tmpurl){
								if(strpos($this->uri->uri_string(), $tmpurl) !== FALSE){
									//TODO hay que mejorar esto
									//$sactive = true;
								}
							}
//							if($active && strpos($this->uri->uri_string(), $surl) !== FALSE){
//								$sactive = true;
//							}
							
							$surl = $surl[0];
						?>
						<li><a href="<?php echo site_url("admin/$surl"); ?>" class="<?php if($sactive) echo "current"; ?>"><?php echo $stitle; ?></a></li>
					<?php endforeach;?>
					</ul>
				<?php endif;?>
			</li>
		<?php endforeach;?>
	</ul> <!-- End #main-nav -->

	<br/><br/><br/><br/><br/><br/><br/><br/>




	<div id="messages" style="display: none"> <!-- Messages are shown when a link with these attributes are clicked: href="#messages" rel="modal"  -->
		
		<h3>3 Messages</h3>

	 
		<p>
			<strong>17th May 2009</strong> by Admin<br />
			Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue.
			<small><a href="#" class="remove-link" title="Remove message">Remove</a></small>
		</p>
	 
		<p>
			<strong>2nd May 2009</strong> by Jane Doe<br />

			Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est.
			<small><a href="#" class="remove-link" title="Remove message">Remove</a></small>
		</p>
	 
		<p>
			<strong>25th April 2009</strong> by Admin<br />
			Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue.
			<small><a href="#" class="remove-link" title="Remove message">Remove</a></small>

		</p>
		
		<form action="" method="post">
			
			<h4>New Message</h4>
			
			<fieldset>
				<textarea class="textarea" name="textfield" cols="79" rows="5"></textarea>
			</fieldset>
			
			<fieldset>
			
				<select name="dropdown" class="small-input">

					<option value="option1">Send to...</option>
					<option value="option2">Everyone</option>
					<option value="option3">Admin</option>
					<option value="option4">Jane Doe</option>
				</select>
				
				<input class="button" type="submit" value="Send" />
				
			</fieldset>

			
		</form>
		
	</div> <!-- End #messages -->
	
</div></div> <!-- End #sidebar -->
